<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>websocket</title>
</head>
<body>
    <button onclick="send()">发送</button>
</body>
<script type="text/javascript">
    var ws = new WebSocket('ws://localhost:3000');
    console.log(ws.readyState)
    ws.onopen = function (evt) {
        console.log('Connection open ...');
        // ws.send('Hello WebSockets!');
    };

    ws.onmessage = function (evt) {
        console.log('Received Message: ' + evt.data);
        // ws.close();
    };

    ws.onclose = function (evt) {
        console.log('Connection closed.');
    };
    var num = 0
    function send() {
        num++
        ws.send('Hello WebSockets!' + num);
    }
</script>
</html>